package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemServiceDealedCasesBinding;
import com.sgb.kjwl.model.entity.enterprise.TransactionCasesEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class DealedCasesPublishAdapter extends BaseRecycleAdapter<TransactionCasesEntity> {

    Context context;
    ItemServiceDealedCasesBinding binding;

    public DealedCasesPublishAdapter(Context context, List<TransactionCasesEntity> datas) {
        super(context, R.layout.item_service_dealed_cases, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, TransactionCasesEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        binding = (ItemServiceDealedCasesBinding) holder.getmBinding();
        binding.tvEdit.setOnClickListener(v -> iOperateCases.call(entity, 1));//编辑
        binding.tvDelete.setOnClickListener(v -> iOperateCases.call(entity, 2));//删除
        binding.tvCategoryValue.setText(entity.getTransactionServiceName());
        binding.tvServiceStatus.setText(entity.getServiceStatus() == -1 ? "办理中" : "已完成");
        binding.tvServiceCustomer.setText(entity.getServeCustomers());
        String provinceCode = entity.getProvincesCode();
        Gson gson = new Gson();
        TransactionCasesEntity.ProvinceCode provinceCodeEntity = gson.fromJson(provinceCode, TransactionCasesEntity.ProvinceCode.class);
        StringBuilder builder = new StringBuilder();
        builder.append(provinceCodeEntity.getProvinceName());
        if (!TextUtils.isEmpty(provinceCodeEntity.getCityName())) {
            builder.append("-").append(provinceCodeEntity.getCityName());
        }
        if (!TextUtils.isEmpty(provinceCodeEntity.getAreaName())) {
            builder.append("-").append(provinceCodeEntity.getAreaName());
        }
        binding.tvServiceCity.setText(builder.toString());

    }

    private IOperateCases iOperateCases;

    public interface IOperateCases {
        void call(TransactionCasesEntity entity, int status);
    }

    public void OnCallPhone(IOperateCases iOperateCases) {
        this.iOperateCases = iOperateCases;
    }
}
